<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>DES算法全解+C语言实现（加密和解密） | 路漫漫其修远兮，吾将上下而求索</title><meta name="keywords" content="算法,数据结构,密码学"><meta name="author" content="Charles Yan"><meta name="copyright" content="Charles Yan"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="密码学之DES算法，包括DES的加密过程，算法细节，以及代码实现。">
<meta property="og:type" content="article">
<meta property="og:title" content="DES算法全解+C语言实现（加密和解密）">
<meta property="og:url" content="https://www.charlesyan.cn/2021/04/17/DES%E7%AE%97%E6%B3%95%E5%85%A8%E8%A7%A3/index.html">
<meta property="og:site_name" content="路漫漫其修远兮，吾将上下而求索">
<meta property="og:description" content="密码学之DES算法，包括DES的加密过程，算法细节，以及代码实现。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=464616017,1330542316&fm=26&gp=0.jpg">
<meta property="article:published_time" content="2021-04-16T16:00:00.000Z">
<meta property="article:modified_time" content="2021-07-04T03:12:04.697Z">
<meta property="article:author" content="Charles Yan">
<meta property="article:tag" content="算法">
<meta property="article:tag" content="数据结构">
<meta property="article:tag" content="密码学">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=464616017,1330542316&fm=26&gp=0.jpg"><link rel="shortcut icon" href="/img/favicon.ico"><link rel="canonical" href="https://www.charlesyan.cn/2021/04/17/DES%E7%AE%97%E6%B3%95%E5%85%A8%E8%A7%A3/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#121212","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: true
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'DES算法全解+C语言实现（加密和解密）',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-07-04 11:12:04'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><link rel="stylesheet" href="/css/selfdesign.css" media="defer" onload="this.media='all'"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="/img/My%20avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">37</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">22</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">12</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fa fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=464616017,1330542316&amp;fm=26&amp;gp=0.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">路漫漫其修远兮，吾将上下而求索</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-coffee"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fa fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fa fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fa fa-film"></i><span> 电影</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">DES算法全解+C语言实现（加密和解密）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-16T16:00:00.000Z" title="发表于 2021-04-17 00:00:00">2021-04-17</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-07-04T03:12:04.697Z" title="更新于 2021-07-04 11:12:04">2021-07-04</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AF%86%E7%A0%81%E5%AD%A6%E5%AE%9E%E9%AA%8C/">密码学实验</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>20分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="DES算法全解+C语言实现（加密和解密）"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="DES算法全解"><a href="#DES算法全解" class="headerlink" title="DES算法全解"></a>DES算法全解</h2><h3 id="一、什么是DES算法"><a href="#一、什么是DES算法" class="headerlink" title="一、什么是DES算法"></a>一、什么是DES算法</h3><ul>
<li><strong>DES</strong>是(Data Encryption Standard）的缩写，为密码体制中的对称密码体制，又被称为美国数据加密标准。</li>
<li>DES是一种分组密码。明文，密文，密钥的分组长度都是64位。</li>
<li>DES是面向二进制的密码算法。因而能够加解密任何形式的计算机数据。</li>
<li>DES是对合运算，因而加密和解密共用同一算法，从而使工程实现的工作量减半</li>
<li>DES的密码结构属于Feistel结构</li>
</ul>
<h3 id="二、DES的加密过程"><a href="#二、DES的加密过程" class="headerlink" title="二、DES的加密过程"></a>二、DES的加密过程</h3><ol>
<li>64位秘钥经子秘钥产生算法产生出16个子秘钥：$K<em>1,K_2,…,K</em>{16}$, 分别供第一次，第二次，… ，第十六次加密迭代使用。</li>
<li>64位明文首先经过初始置换$IP（Initial\quad permutation）$，将数据打乱重新排列并分成左右两半，左边32位构成$L_0$，右边32位构成$R_0$。</li>
<li>由加密函数$f$实现子密钥$K_1$对$R_0$的加密，结果为32位的数据组$f(R_0,K_1)$。$f(R_0,K_1)$再与$L_0$模2相加，又得到一个有32位的数据组$L_0\bigoplus f(R_0,K_1)$。以$L_0\bigoplus f(R_0,K_1)$作为第二次加密迭代的$R_1$，以$R_0$作为第二次加密迭代的$L_1$。至此，第一次加密迭代结束。</li>
<li>第二次加密迭代至第十六次加密迭代分别用子密钥$K<em>2，…，K</em>{16}$进行，其过程与第一次加密迭代相同。</li>
<li>第十六次加密迭代结束后，产生一个64位的数据组。以其左边32位作为$L<em>{16}$，以其右边32位作为$R</em>{16}$，两者合并在经过逆初始置换<strong>$\color{red}{IP^{-1} }$</strong>，将数据重新排列，便得到64位密文。至此加密过程全部结束。</li>
</ol>
<h3 id="三、DES的算法细节"><a href="#三、DES的算法细节" class="headerlink" title="三、DES的算法细节"></a>三、DES的算法细节</h3><p>下面我们详细的介绍算法细节。</p>
<h4 id="1-创建16个子秘钥，每个长48比特"><a href="#1-创建16个子秘钥，每个长48比特" class="headerlink" title="1.     创建16个子秘钥，每个长48比特"></a>1.     创建16个子秘钥，每个长48比特</h4><p>创建子密钥过程大致流程图如下：</p>
<p><img src="https://i.loli.net/2021/04/13/FkdKeIb3ylh7YnZ.jpg" alt="流程" style="zoom:70%;" /></p>
<p>64位秘钥我们已经给出，现在依次介绍置换选择1，，置换选择2，循环左移。</p>
<ol>
<li><p><strong>置换选择1</strong></p>
<ul>
<li><p>64位秘钥分为8个字节，每个字节的前7位是真正的秘钥位，第8位是奇偶校验位。奇偶校验位可以从前7位秘钥位计算得出，不是随机的，因而不起秘钥的作用。奇偶校验位的作用在于可检测秘钥中是否有错误，确保秘钥的完整性，因此，DES真正的秘钥只有56位。</p>
</li>
<li><p>置换选择1的作用，一是从64位秘钥中去掉8个奇偶校验位，二是把其余56位秘钥位打乱重新排，且将前28位作为$C_0$，后28位作为$D_0$。</p>
</li>
<li><p>置换选择1规定：$C_0$的各位依次为原秘钥中的第57，49，…，1，…，44，36位。$D_0$的各位依次为原秘钥中的第63，55，…，7，…，12，4位，具体矩阵如下：</p>
<p><img src="https://i.loli.net/2021/04/13/oDOfBns9UCNzHa4.jpg" alt="CBCEA409-810F-4561-8D56-F37A664CD81D.png"></p>
</li>
</ul>
</li>
</ol>
<p><strong>例：秘钥为12345678</strong></p>
<p>以ASCLL码的形式转化为二进制：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">00110001</span> <span class="number">00110010</span> <span class="number">00110011</span> <span class="number">00110100</span> <span class="number">00110101</span> <span class="number">00110110</span> <span class="number">00110111</span> <span class="number">00111000</span></span><br></pre></td></tr></table></figure>
<p>那么，此秘钥置换选择1后的结果为：</p>
<p><strong>置换选择1：</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">00000000</span> <span class="number">00000000</span> <span class="number">11111111</span> <span class="number">11110110</span> <span class="number">01100111</span> <span class="number">1001000</span> <span class="number">00001111</span></span><br></pre></td></tr></table></figure>
<p>$C_0$</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0000000000000000111111111111</span></span><br></pre></td></tr></table></figure>
<p>$D_0$</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0110011001111000100000001111</span></span><br></pre></td></tr></table></figure>
<ol>
<li>置换选择2<ul>
<li>将$C_i$和$D_i$合并成一个56位的中间数据，置换选择2从中选择出一个48位的子密钥$K_i$。置换选择2的矩阵如下图</li>
<li>置换选择2规定子密钥$K_i$中的第1，2，…，48位依次是这个56位中间数据中的第14，17，…，5，3，…，29，32位。</li>
</ul>
</li>
</ol>
<p><img src="https://i.loli.net/2021/04/13/UIjui52XOpSKMVG.jpg" alt="置换选择2" style="zoom:50%;" /></p>
<ol>
<li>循环左移：将密钥（除第一位）整体左移一位，将第一位移动至最后一位。循环左移位数表如下：<img src="https://i.loli.net/2021/04/13/A6mZS13PtH7VoMn.jpg" alt="循环左移位数表" style="zoom:80%;" /></li>
</ol>
<p>16轮子密钥生成结果如下：</p>
<h4 id="2-明文初始变换"><a href="#2-明文初始变换" class="headerlink" title="2. 明文初始变换"></a>2. 明文初始变换</h4><p>初始置换$IP$是DES的第一步密码变换，初始置换的作用在于将64位明文打乱重排，并陈诚左右两半，左边32位作为$L_0$,右边32位作为$R_0$。供后面的加密迭代使用。初始置换$IP$的矩阵如下：（道理同上）</p>
<p><img src="https://i.loli.net/2021/04/13/3hQYXmSt5iyRU6W.jpg" alt="初始置换IP" style="zoom:50%;" /></p>
<h4 id="3-加密函数"><a href="#3-加密函数" class="headerlink" title="3. 加密函数"></a>3. 加密函数</h4><p>加密函数是DES的核心部分。它的作用是在第$i$次加密迭代中用子密钥$K<em>i$对$R</em>{i-1}$进行加密。</p>
<p>在第$i$次迭代加密中选择运算$E$对32位的$R<em>{i-1}$的各位进行选择和排列，产生一个48位的结果，此结果与子密钥$K_i$模2相加，然后送入代替函数组$S$。代替函数组由8个代替函数（也称S盒子）组成，每个S盒子有6位输入，产生4位的输出。8个S盒子的输出合并，结果得到一个32位的数据组。此数据组在经过置换运算P，将其各位打乱重排，置换运算P的输出便是加密函数的输出$f(R</em>{i-1},K_i)$。</p>
<ol>
<li><p><strong>选择运算E</strong>对32位的数据组A的各位进行选择和排列，产生一个48位的结果。他是一种扩展运算，其矩阵如图：</p>
<p><img src="https://i.loli.net/2021/04/13/E7qNenOyYbIAPhK.jpg" alt="选择运算" style="zoom:30%;" /></p>
</li>
<li><p><strong>代替函数组S</strong>由8个代替函数（也称S盒子）组成，8个S盒分别记为，$S_1,S_2,…,S_8$。代替函数组的输入时一个48位的数据，从第一位到第48位依次加到8个S盒的输入端，每个S盒有一个代替矩阵，规定了其输出与输入的代替规则。代替矩阵有4行16列，每行都是0到15这16个数字，但每行的数字排列都不同，而且8个代替矩阵彼此也不同，每个S盒有6位输入，产生4位的输出。S盒运算的结果是用输出数据代替了输入数据，所以称其为代替函数。</p>
<p>​        <strong>S盒的代替规则：</strong>S盒的六位输入中，第一位和第六位组成二进制数并转化为十进制数代表选中的行号，其余四位组成二进制数并转化为十进制数代表选中的列号。那么被选中的那个数就是要输出的数（转化为二进制）。</p>
<p>​        以$S<em>1$为例，如果输入的是101011，第一位与第六位组成行号 $11</em>{(2)} = 3<em>{(10)}$ ，选中第三行，其余四位组成列号 $0101</em>{(2)} = 5_{(10)}$，选中第五列，交点数字是9，则$S_1$的输出是1001。</p>
</li>
<li><p><strong>置换运算$P$：</strong>置换运算吧S盒输出的32位数据打乱重排，得到32位的加密函数输出。用P置换来提供扩散，把S盒的混淆作用扩散开来。此时，$R<em>{i-1}$变成$L</em>{i}$，$L_i$再和置换运算P得出来的32位数据做$\bigoplus$运算，得到$R_i$。置换矩阵如图：</p>
</li>
<li><strong>逆初始置换$IP^{-1}$：</strong>是初始置换的逆置换，它把第十六次加密迭代的结果打乱重排（这里$R<em>{16}$与$L</em>{16}$互换），形成64位密文。至此，加密过程完全结束。</li>
</ol>
<p><img src="https://i.loli.net/2021/04/14/FqoekW3m52puVa8.jpg" alt="672C1E7DBC59E27A94DF29AF58498D4B.jpg" style="zoom:50%;" /></p>
<p><img src="https://i.loli.net/2021/04/14/dmfvIlgerVpCtOZ.jpg" alt="4C5C280892CC879204AC6F800285FC99.jpg" style="zoom:50%;" /></p>
<p><img src="https://i.loli.net/2021/04/14/bW1TgLGxdk7SpDm.jpg" alt="930EEC1CD39D6D844DFD3167F84CFBC4.jpg" style="zoom:50%;" /></p>
<p><img src="https://i.loli.net/2021/04/14/mLhfHUMIeXnO4rd.jpg" alt="3AF7BA7A091100A2732266480E846A0A.jpg" style="zoom:50%;" /></p>
<h4 id="4-解密过程"><a href="#4-解密过程" class="headerlink" title="4. 解密过程"></a>4. 解密过程</h4><p>​        由于DES是对合运算，所以解密和加密可共用同一个运算，只是子密钥使用的顺序不同。把64位密文当做明文输入，而且第一次解密迭代是用子密钥$K_{16}$，第十六次解密迭代使用子密钥$K_1$，最后的输出便是64位明文。</p>
<p><strong>代码如下：</strong></p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  main.cpp</span></span><br><span class="line"><span class="comment">//  DES算法</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"><span class="comment">//  Created by CharlesYan on 2021/4/13.</span></span><br><span class="line"><span class="comment">//</span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="comment">//16-wheel secret key structural body</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Secret_Key</span>&#123;</span></span><br><span class="line">    <span class="keyword">int</span> subKey[<span class="number">56</span>] = &#123;&#125;;</span><br><span class="line">    <span class="keyword">int</span> C[<span class="number">28</span>];</span><br><span class="line">    <span class="keyword">int</span> D[<span class="number">28</span>];</span><br><span class="line">&#125;Secret_KeyOf16[<span class="number">17</span>];<span class="comment">//save the 16-wheel sercet key,and the zero flag in order to save the first substitution selection.</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// save the process of encryption</span></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Encryption</span>&#123;</span></span><br><span class="line">    <span class="keyword">int</span> select_Operation[<span class="number">48</span>];</span><br><span class="line">    <span class="keyword">int</span> secretKey_Operation[<span class="number">48</span>];</span><br><span class="line">    <span class="keyword">int</span> boxOf_S[<span class="number">32</span>];</span><br><span class="line">    <span class="keyword">int</span> L[<span class="number">32</span>];</span><br><span class="line">    <span class="keyword">int</span> R[<span class="number">32</span>];</span><br><span class="line">&#125;Encryption_Pro[<span class="number">17</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> result_Secret[<span class="number">64</span>] = &#123;&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//substitution selection table 1(置换选择1)</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> subSelect_table1[<span class="number">56</span>] = &#123;</span><br><span class="line">    <span class="number">57</span>,<span class="number">49</span>,<span class="number">41</span>,<span class="number">33</span>,<span class="number">25</span>,<span class="number">17</span>, <span class="number">9</span>, <span class="number">1</span>,<span class="number">58</span>,<span class="number">50</span>,<span class="number">42</span>,<span class="number">34</span>,<span class="number">26</span>,<span class="number">18</span>,</span><br><span class="line">    <span class="number">10</span>, <span class="number">2</span>,<span class="number">59</span>,<span class="number">51</span>,<span class="number">43</span>,<span class="number">35</span>,<span class="number">27</span>,<span class="number">19</span>,<span class="number">11</span>, <span class="number">3</span>,<span class="number">60</span>,<span class="number">52</span>,<span class="number">44</span>,<span class="number">36</span>,</span><br><span class="line">    <span class="number">63</span>,<span class="number">55</span>,<span class="number">47</span>,<span class="number">39</span>,<span class="number">31</span>,<span class="number">23</span>,<span class="number">15</span>, <span class="number">7</span>,<span class="number">62</span>,<span class="number">54</span>,<span class="number">46</span>,<span class="number">38</span>,<span class="number">30</span>,<span class="number">22</span>,</span><br><span class="line">    <span class="number">14</span>, <span class="number">6</span>,<span class="number">61</span>,<span class="number">53</span>,<span class="number">45</span>,<span class="number">37</span>,<span class="number">29</span>,<span class="number">21</span>,<span class="number">13</span>, <span class="number">5</span>,<span class="number">28</span>,<span class="number">20</span>,<span class="number">12</span>, <span class="number">4</span></span><br><span class="line">   &#125;;</span><br><span class="line"><span class="comment">//substitution selection table 2(置换选择2)</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> subSelect_table2[<span class="number">48</span>]=&#123;</span><br><span class="line"> <span class="number">14</span>,<span class="number">17</span>,<span class="number">11</span>,<span class="number">24</span>, <span class="number">1</span>, <span class="number">5</span>, <span class="number">3</span>,<span class="number">28</span>,<span class="number">15</span>, <span class="number">6</span>,<span class="number">21</span>,<span class="number">10</span>,</span><br><span class="line"> <span class="number">23</span>,<span class="number">19</span>,<span class="number">12</span>, <span class="number">4</span>,<span class="number">26</span>, <span class="number">8</span>,<span class="number">16</span>, <span class="number">7</span>,<span class="number">27</span>,<span class="number">20</span>,<span class="number">13</span>, <span class="number">2</span>,</span><br><span class="line"> <span class="number">41</span>,<span class="number">52</span>,<span class="number">31</span>,<span class="number">37</span>,<span class="number">47</span>,<span class="number">55</span>,<span class="number">30</span>,<span class="number">40</span>,<span class="number">51</span>,<span class="number">45</span>,<span class="number">33</span>,<span class="number">48</span>,</span><br><span class="line"> <span class="number">44</span>,<span class="number">49</span>,<span class="number">39</span>,<span class="number">56</span>,<span class="number">34</span>,<span class="number">53</span>,<span class="number">46</span>,<span class="number">42</span>,<span class="number">50</span>,<span class="number">36</span>,<span class="number">29</span>,<span class="number">32</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">//Move left shift bits table(循环左移位数表)</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> moveLeft_table[<span class="number">17</span>] = &#123;<span class="number">0</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">2</span>,<span class="number">1</span>&#125;;</span><br><span class="line"><span class="comment">//initial substitution IP</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> init_subIP[<span class="number">64</span>] = &#123;</span><br><span class="line"><span class="number">58</span>,<span class="number">50</span>,<span class="number">42</span>,<span class="number">34</span>,<span class="number">26</span>,<span class="number">18</span>,<span class="number">10</span>, <span class="number">2</span>,<span class="number">60</span>,<span class="number">52</span>,<span class="number">44</span>,<span class="number">36</span>,<span class="number">28</span>,<span class="number">20</span>,<span class="number">12</span>, <span class="number">4</span>,</span><br><span class="line"><span class="number">62</span>,<span class="number">54</span>,<span class="number">46</span>,<span class="number">38</span>,<span class="number">30</span>,<span class="number">22</span>,<span class="number">14</span>, <span class="number">6</span>,<span class="number">64</span>,<span class="number">56</span>,<span class="number">48</span>,<span class="number">40</span>,<span class="number">32</span>,<span class="number">24</span>,<span class="number">16</span>, <span class="number">8</span>,</span><br><span class="line"><span class="number">57</span>,<span class="number">49</span>,<span class="number">41</span>,<span class="number">33</span>,<span class="number">25</span>,<span class="number">17</span>, <span class="number">9</span>, <span class="number">1</span>,<span class="number">59</span>,<span class="number">51</span>,<span class="number">43</span>,<span class="number">35</span>,<span class="number">27</span>,<span class="number">19</span>,<span class="number">11</span>, <span class="number">3</span>,</span><br><span class="line"><span class="number">61</span>,<span class="number">53</span>,<span class="number">45</span>,<span class="number">37</span>,<span class="number">29</span>,<span class="number">21</span>,<span class="number">13</span>, <span class="number">5</span>,<span class="number">63</span>,<span class="number">55</span>,<span class="number">47</span>,<span class="number">39</span>,<span class="number">31</span>,<span class="number">23</span>,<span class="number">15</span>, <span class="number">7</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">//selection operation E</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> sel_E[<span class="number">48</span>] = &#123;</span><br><span class="line"><span class="number">32</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">7</span>, <span class="number">8</span>, <span class="number">9</span>,</span><br><span class="line"><span class="number">8</span>, <span class="number">9</span>,<span class="number">10</span>,<span class="number">11</span>,<span class="number">12</span>,<span class="number">13</span>,<span class="number">12</span>,<span class="number">13</span>,<span class="number">14</span>,<span class="number">15</span>,<span class="number">16</span>,<span class="number">17</span>,</span><br><span class="line"><span class="number">16</span>,<span class="number">17</span>,<span class="number">18</span>,<span class="number">19</span>,<span class="number">20</span>,<span class="number">21</span>,<span class="number">20</span>,<span class="number">21</span>,<span class="number">22</span>,<span class="number">23</span>,<span class="number">24</span>,<span class="number">25</span>,</span><br><span class="line"><span class="number">24</span>,<span class="number">25</span>,<span class="number">26</span>,<span class="number">27</span>,<span class="number">28</span>,<span class="number">29</span>,<span class="number">28</span>,<span class="number">29</span>,<span class="number">30</span>,<span class="number">31</span>,<span class="number">32</span>, <span class="number">1</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">// Box of S 3D array</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> BoxOf_S[<span class="number">8</span>][<span class="number">4</span>][<span class="number">16</span>]=&#123;</span><br><span class="line"> <span class="comment">//S1</span></span><br><span class="line"> <span class="number">14</span>, <span class="number">4</span>,<span class="number">13</span>, <span class="number">1</span>, <span class="number">2</span>,<span class="number">15</span>,<span class="number">11</span>, <span class="number">8</span>, <span class="number">3</span>,<span class="number">10</span>, <span class="number">6</span>,<span class="number">12</span>, <span class="number">5</span>, <span class="number">9</span>, <span class="number">0</span>, <span class="number">7</span>,</span><br><span class="line">  <span class="number">0</span>,<span class="number">15</span>, <span class="number">7</span>, <span class="number">4</span>,<span class="number">14</span>, <span class="number">2</span>,<span class="number">13</span>, <span class="number">1</span>,<span class="number">10</span>, <span class="number">6</span>,<span class="number">12</span>,<span class="number">11</span>, <span class="number">9</span>, <span class="number">5</span>, <span class="number">3</span>, <span class="number">8</span>,</span><br><span class="line">  <span class="number">4</span>, <span class="number">1</span>,<span class="number">14</span>, <span class="number">8</span>,<span class="number">13</span>, <span class="number">6</span>, <span class="number">2</span>,<span class="number">11</span>,<span class="number">15</span>,<span class="number">12</span>, <span class="number">9</span>, <span class="number">7</span>, <span class="number">3</span>,<span class="number">10</span>, <span class="number">5</span>, <span class="number">0</span>,</span><br><span class="line"> <span class="number">15</span>,<span class="number">12</span>, <span class="number">8</span>, <span class="number">2</span>, <span class="number">4</span>, <span class="number">9</span>, <span class="number">1</span>, <span class="number">7</span>, <span class="number">5</span>,<span class="number">11</span>, <span class="number">3</span>,<span class="number">14</span>,<span class="number">10</span>, <span class="number">0</span>, <span class="number">6</span>,<span class="number">13</span>,</span><br><span class="line"> <span class="comment">//S2</span></span><br><span class="line"> <span class="number">15</span>, <span class="number">1</span>, <span class="number">8</span>,<span class="number">14</span>, <span class="number">6</span>,<span class="number">11</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">9</span>, <span class="number">7</span>, <span class="number">2</span>,<span class="number">13</span>,<span class="number">12</span>, <span class="number">0</span>, <span class="number">5</span>,<span class="number">10</span>,</span><br><span class="line">  <span class="number">3</span>,<span class="number">13</span>, <span class="number">4</span>, <span class="number">7</span>,<span class="number">15</span>, <span class="number">2</span>, <span class="number">8</span>,<span class="number">14</span>,<span class="number">12</span>, <span class="number">0</span>, <span class="number">1</span>,<span class="number">10</span>, <span class="number">6</span>, <span class="number">9</span>,<span class="number">11</span>, <span class="number">5</span>,</span><br><span class="line">  <span class="number">0</span>,<span class="number">14</span>, <span class="number">7</span>,<span class="number">11</span>,<span class="number">10</span>, <span class="number">4</span>,<span class="number">13</span>, <span class="number">1</span>, <span class="number">5</span>, <span class="number">8</span>,<span class="number">12</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">3</span>, <span class="number">2</span>,<span class="number">15</span>,</span><br><span class="line"> <span class="number">13</span>, <span class="number">8</span>,<span class="number">10</span>, <span class="number">1</span>, <span class="number">3</span>,<span class="number">15</span>, <span class="number">4</span>, <span class="number">2</span>,<span class="number">11</span>, <span class="number">6</span>, <span class="number">7</span>,<span class="number">12</span>, <span class="number">0</span>, <span class="number">5</span>,<span class="number">14</span>, <span class="number">9</span>,</span><br><span class="line"> <span class="comment">//S3</span></span><br><span class="line"> <span class="number">10</span>, <span class="number">0</span>, <span class="number">9</span>,<span class="number">14</span>, <span class="number">6</span>, <span class="number">3</span>,<span class="number">15</span>, <span class="number">5</span>, <span class="number">1</span>,<span class="number">13</span>,<span class="number">12</span>, <span class="number">7</span>,<span class="number">11</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">8</span>,</span><br><span class="line"> <span class="number">13</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">9</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">6</span>,<span class="number">10</span>, <span class="number">2</span>, <span class="number">8</span>, <span class="number">5</span>,<span class="number">14</span>,<span class="number">12</span>,<span class="number">11</span>,<span class="number">15</span>, <span class="number">1</span>,</span><br><span class="line"> <span class="number">13</span>, <span class="number">6</span>, <span class="number">4</span>, <span class="number">9</span>, <span class="number">8</span>,<span class="number">15</span>, <span class="number">3</span>, <span class="number">0</span>,<span class="number">11</span>, <span class="number">1</span>, <span class="number">2</span>,<span class="number">12</span>, <span class="number">5</span>,<span class="number">10</span>,<span class="number">14</span>, <span class="number">7</span>,</span><br><span class="line">  <span class="number">1</span>,<span class="number">10</span>,<span class="number">13</span>, <span class="number">0</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">8</span>, <span class="number">7</span>, <span class="number">4</span>,<span class="number">15</span>,<span class="number">14</span>, <span class="number">3</span>,<span class="number">11</span>, <span class="number">5</span>, <span class="number">2</span>,<span class="number">12</span>,</span><br><span class="line"> <span class="comment">//S4</span></span><br><span class="line">  <span class="number">7</span>,<span class="number">13</span>,<span class="number">14</span>, <span class="number">3</span>, <span class="number">0</span>, <span class="number">6</span>, <span class="number">9</span>,<span class="number">10</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">8</span>, <span class="number">5</span>,<span class="number">11</span>,<span class="number">12</span>, <span class="number">4</span>,<span class="number">15</span>,</span><br><span class="line"> <span class="number">13</span>, <span class="number">8</span>,<span class="number">11</span>, <span class="number">5</span>, <span class="number">6</span>,<span class="number">15</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">7</span>, <span class="number">2</span>,<span class="number">12</span>, <span class="number">1</span>,<span class="number">10</span>,<span class="number">14</span>, <span class="number">9</span>,</span><br><span class="line"> <span class="number">10</span>, <span class="number">6</span>, <span class="number">9</span>, <span class="number">0</span>,<span class="number">12</span>,<span class="number">11</span>, <span class="number">7</span>,<span class="number">13</span>,<span class="number">15</span>, <span class="number">1</span>, <span class="number">3</span>,<span class="number">14</span>, <span class="number">5</span>, <span class="number">2</span>, <span class="number">8</span>, <span class="number">4</span>,</span><br><span class="line">  <span class="number">3</span>,<span class="number">15</span>, <span class="number">0</span>, <span class="number">6</span>,<span class="number">10</span>, <span class="number">1</span>,<span class="number">13</span>, <span class="number">8</span>, <span class="number">9</span>, <span class="number">4</span>, <span class="number">5</span>,<span class="number">11</span>,<span class="number">12</span>, <span class="number">7</span>, <span class="number">2</span>,<span class="number">14</span>,</span><br><span class="line"> <span class="comment">//S5</span></span><br><span class="line">  <span class="number">2</span>,<span class="number">12</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">7</span>,<span class="number">10</span>,<span class="number">11</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">5</span>, <span class="number">3</span>,<span class="number">15</span>,<span class="number">13</span>, <span class="number">0</span>,<span class="number">14</span>, <span class="number">9</span>,</span><br><span class="line"> <span class="number">14</span>,<span class="number">11</span>, <span class="number">2</span>,<span class="number">12</span>, <span class="number">4</span>, <span class="number">7</span>,<span class="number">13</span>, <span class="number">1</span>, <span class="number">5</span>, <span class="number">0</span>,<span class="number">15</span>,<span class="number">10</span>, <span class="number">3</span>, <span class="number">9</span>, <span class="number">8</span>, <span class="number">6</span>,</span><br><span class="line">  <span class="number">4</span>, <span class="number">2</span>, <span class="number">1</span>,<span class="number">11</span>,<span class="number">10</span>,<span class="number">13</span>, <span class="number">7</span>, <span class="number">8</span>,<span class="number">15</span>, <span class="number">9</span>,<span class="number">12</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">3</span>, <span class="number">0</span>,<span class="number">14</span>,</span><br><span class="line"> <span class="number">11</span>, <span class="number">8</span>,<span class="number">12</span>, <span class="number">7</span>, <span class="number">1</span>,<span class="number">14</span>, <span class="number">2</span>,<span class="number">13</span>, <span class="number">6</span>,<span class="number">15</span>, <span class="number">0</span>, <span class="number">9</span>,<span class="number">10</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">3</span>,</span><br><span class="line"> <span class="comment">//S6</span></span><br><span class="line"> <span class="number">12</span>, <span class="number">1</span>,<span class="number">10</span>,<span class="number">15</span>, <span class="number">9</span>, <span class="number">2</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">0</span>,<span class="number">13</span>, <span class="number">3</span>, <span class="number">4</span>,<span class="number">14</span>, <span class="number">7</span>, <span class="number">5</span>,<span class="number">11</span>,</span><br><span class="line"> <span class="number">10</span>,<span class="number">15</span>, <span class="number">4</span>, <span class="number">2</span>, <span class="number">7</span>,<span class="number">12</span>, <span class="number">9</span>, <span class="number">5</span>, <span class="number">6</span>, <span class="number">1</span>,<span class="number">13</span>,<span class="number">14</span>, <span class="number">0</span>,<span class="number">11</span>, <span class="number">3</span>, <span class="number">8</span>,</span><br><span class="line">  <span class="number">9</span>,<span class="number">14</span>,<span class="number">15</span>, <span class="number">5</span>, <span class="number">2</span>, <span class="number">8</span>,<span class="number">12</span>, <span class="number">3</span>, <span class="number">7</span>, <span class="number">0</span>, <span class="number">4</span>,<span class="number">10</span>, <span class="number">1</span>,<span class="number">13</span>,<span class="number">11</span>, <span class="number">6</span>,</span><br><span class="line">     <span class="number">4</span>, <span class="number">3</span>, <span class="number">2</span>,<span class="number">12</span>, <span class="number">9</span>, <span class="number">5</span>,<span class="number">15</span>,<span class="number">10</span>,<span class="number">11</span>,<span class="number">14</span>, <span class="number">1</span>, <span class="number">7</span>, <span class="number">6</span>, <span class="number">0</span>, <span class="number">8</span>,<span class="number">13</span>,</span><br><span class="line"> <span class="comment">//S7</span></span><br><span class="line">  <span class="number">4</span>,<span class="number">11</span>, <span class="number">2</span>,<span class="number">14</span>,<span class="number">15</span>, <span class="number">0</span>, <span class="number">8</span>,<span class="number">13</span>, <span class="number">3</span>,<span class="number">12</span>, <span class="number">9</span>, <span class="number">7</span>, <span class="number">5</span>,<span class="number">10</span>, <span class="number">6</span>, <span class="number">1</span>,</span><br><span class="line"> <span class="number">13</span>, <span class="number">0</span>,<span class="number">11</span>, <span class="number">7</span>, <span class="number">4</span>, <span class="number">9</span>, <span class="number">1</span>,<span class="number">10</span>,<span class="number">14</span>, <span class="number">3</span>, <span class="number">5</span>,<span class="number">12</span>, <span class="number">2</span>,<span class="number">15</span>, <span class="number">8</span>, <span class="number">6</span>,</span><br><span class="line">  <span class="number">1</span>, <span class="number">4</span>,<span class="number">11</span>,<span class="number">13</span>,<span class="number">12</span>, <span class="number">3</span>, <span class="number">7</span>,<span class="number">14</span>,<span class="number">10</span>,<span class="number">15</span>, <span class="number">6</span>, <span class="number">8</span>, <span class="number">0</span>, <span class="number">5</span>, <span class="number">9</span>, <span class="number">2</span>,</span><br><span class="line">  <span class="number">6</span>,<span class="number">11</span>,<span class="number">13</span>, <span class="number">8</span>, <span class="number">1</span>, <span class="number">4</span>,<span class="number">10</span>, <span class="number">7</span>, <span class="number">9</span>, <span class="number">5</span>, <span class="number">0</span>,<span class="number">15</span>,<span class="number">14</span>, <span class="number">2</span>, <span class="number">3</span>,<span class="number">12</span>,</span><br><span class="line"> <span class="comment">//S8</span></span><br><span class="line"> <span class="number">13</span>, <span class="number">2</span>, <span class="number">8</span>, <span class="number">4</span>, <span class="number">6</span>,<span class="number">15</span>,<span class="number">11</span>, <span class="number">1</span>,<span class="number">10</span>, <span class="number">9</span>, <span class="number">3</span>,<span class="number">14</span>, <span class="number">5</span>, <span class="number">0</span>,<span class="number">12</span>, <span class="number">7</span>,</span><br><span class="line">  <span class="number">1</span>,<span class="number">15</span>,<span class="number">13</span>, <span class="number">8</span>,<span class="number">10</span>, <span class="number">3</span>, <span class="number">7</span>, <span class="number">4</span>,<span class="number">12</span>, <span class="number">5</span>, <span class="number">6</span>,<span class="number">11</span>, <span class="number">0</span>,<span class="number">14</span>, <span class="number">9</span>, <span class="number">2</span>,</span><br><span class="line">  <span class="number">7</span>,<span class="number">11</span>, <span class="number">4</span>, <span class="number">1</span>, <span class="number">9</span>,<span class="number">12</span>,<span class="number">14</span>, <span class="number">2</span>, <span class="number">0</span>, <span class="number">6</span>,<span class="number">10</span>,<span class="number">13</span>,<span class="number">15</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">8</span>,</span><br><span class="line">  <span class="number">2</span>, <span class="number">1</span>,<span class="number">14</span>, <span class="number">7</span>, <span class="number">4</span>,<span class="number">10</span>, <span class="number">8</span>,<span class="number">13</span>,<span class="number">15</span>,<span class="number">12</span>, <span class="number">9</span>, <span class="number">0</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">6</span>,<span class="number">11</span></span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment">//substitution IP</span></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">char</span> P_Table[<span class="number">32</span>]=&#123;</span><br><span class="line"> <span class="number">16</span>, <span class="number">7</span>,<span class="number">20</span>,<span class="number">21</span>,<span class="number">29</span>,<span class="number">12</span>,<span class="number">28</span>,<span class="number">17</span>, <span class="number">1</span>,<span class="number">15</span>,<span class="number">23</span>,<span class="number">26</span>, <span class="number">5</span>,<span class="number">18</span>,<span class="number">31</span>,<span class="number">10</span>,</span><br><span class="line">  <span class="number">2</span>, <span class="number">8</span>,<span class="number">24</span>,<span class="number">14</span>,<span class="number">32</span>,<span class="number">27</span>, <span class="number">3</span>, <span class="number">9</span>,<span class="number">19</span>,<span class="number">13</span>,<span class="number">30</span>, <span class="number">6</span>,<span class="number">22</span>,<span class="number">11</span>, <span class="number">4</span>,<span class="number">25</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> IPR_Table[<span class="number">64</span>]=&#123;</span><br><span class="line"> <span class="number">40</span>, <span class="number">8</span>,<span class="number">48</span>,<span class="number">16</span>,<span class="number">56</span>,<span class="number">24</span>,<span class="number">64</span>,<span class="number">32</span>,<span class="number">39</span>, <span class="number">7</span>,<span class="number">47</span>,<span class="number">15</span>,<span class="number">55</span>,<span class="number">23</span>,<span class="number">63</span>,<span class="number">31</span>,</span><br><span class="line"> <span class="number">38</span>, <span class="number">6</span>,<span class="number">46</span>,<span class="number">14</span>,<span class="number">54</span>,<span class="number">22</span>,<span class="number">62</span>,<span class="number">30</span>,<span class="number">37</span>, <span class="number">5</span>,<span class="number">45</span>,<span class="number">13</span>,<span class="number">53</span>,<span class="number">21</span>,<span class="number">61</span>,<span class="number">29</span>,</span><br><span class="line"> <span class="number">36</span>, <span class="number">4</span>,<span class="number">44</span>,<span class="number">12</span>,<span class="number">52</span>,<span class="number">20</span>,<span class="number">60</span>,<span class="number">28</span>,<span class="number">35</span>, <span class="number">3</span>,<span class="number">43</span>,<span class="number">11</span>,<span class="number">51</span>,<span class="number">19</span>,<span class="number">59</span>,<span class="number">27</span>,</span><br><span class="line"> <span class="number">34</span>, <span class="number">2</span>,<span class="number">42</span>,<span class="number">10</span>,<span class="number">50</span>,<span class="number">18</span>,<span class="number">58</span>,<span class="number">26</span>,<span class="number">33</span>, <span class="number">1</span>,<span class="number">41</span>, <span class="number">9</span>,<span class="number">49</span>,<span class="number">17</span>,<span class="number">57</span>,<span class="number">25</span></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//Convert an 8-byte key or plaintext to 64-bit binary</span></span><br><span class="line"><span class="function"><span class="keyword">int</span>* <span class="title">ChangeToBit</span><span class="params">(<span class="keyword">char</span> code[],<span class="keyword">int</span> n)</span></span>;</span><br><span class="line"><span class="comment">//Subfunction：change Byte to 8-bit binary</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> * <span class="title">Change_bit</span><span class="params">(<span class="keyword">int</span> a)</span></span>;</span><br><span class="line"><span class="comment">//create 16-wheel secret key and save them to Secret_KeyOf16</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">set_16wheelKey</span><span class="params">(<span class="keyword">int</span> *bit_SecretKey)</span></span>;</span><br><span class="line"><span class="comment">//the first step of encryption,set R0, as we know, we will not need L0 later.</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">first_StepEncryption</span><span class="params">(<span class="keyword">int</span> *bit_PlainText)</span></span>;</span><br><span class="line"><span class="comment">//encryption, return the result of encryption</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">other_StepEncrtption</span><span class="params">(<span class="keyword">int</span> flag)</span></span>;</span><br><span class="line"><span class="comment">//Box of S operation</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Box_operation</span><span class="params">(<span class="keyword">int</span> *a,<span class="keyword">int</span> n)</span></span>;</span><br><span class="line"><span class="comment">// Box of S change byte to bit</span></span><br><span class="line"><span class="function"><span class="keyword">int</span> * <span class="title">Change_bit_S</span><span class="params">(<span class="keyword">int</span> a)</span></span>;</span><br><span class="line"><span class="comment">//IPR_table operation</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">IPR_Operation</span><span class="params">(<span class="keyword">int</span> result[])</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print</span><span class="params">(<span class="keyword">int</span> flag)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Pri_ChangeToByte</span><span class="params">(<span class="keyword">int</span> secretKey[])</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">char</span> my_Plaintext[<span class="number">9</span>] = &#123;&#125;;<span class="comment">//save plaintext and the last one is &#x27;\0&#x27;</span></span><br><span class="line">    <span class="keyword">char</span> my_SecretKey[<span class="number">9</span>] = &#123;&#125;;<span class="comment">//save secretkey</span></span><br><span class="line">    cout&lt;&lt;<span class="string">&quot;Please input the plaintext of 8 byte:&quot;</span>&lt;&lt;endl;</span><br><span class="line">    cin.<span class="built_in">get</span>(my_Plaintext,<span class="number">9</span>);</span><br><span class="line">    cin.<span class="built_in">get</span>();<span class="comment">// getchar();</span></span><br><span class="line">    cout&lt;&lt;<span class="string">&quot;Please input the secret key of 8 byte&quot;</span>&lt;&lt;endl;</span><br><span class="line">    cin.<span class="built_in">get</span>(my_SecretKey,<span class="number">9</span>);</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">    <span class="comment">//8-byte SecretKey turn into 64-bit binary</span></span><br><span class="line">    <span class="keyword">int</span> *bit_SecretKey = <span class="built_in">ChangeToBit</span>(my_SecretKey, <span class="number">8</span>);</span><br><span class="line">    <span class="comment">//create 16-wheel secret key.</span></span><br><span class="line">    <span class="built_in">set_16wheelKey</span>(bit_SecretKey);</span><br><span class="line">    <span class="comment">//8-byte SecretKey turn into 64-bit binary</span></span><br><span class="line">    <span class="keyword">int</span> *bit_Plaintext = <span class="built_in">ChangeToBit</span>(my_Plaintext, <span class="number">8</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//Encryption</span></span><br><span class="line">    <span class="built_in">first_StepEncryption</span>(bit_Plaintext);</span><br><span class="line">    <span class="built_in">other_StepEncrtption</span>(<span class="number">0</span>);<span class="comment">//the 0 is meant encryption</span></span><br><span class="line">    <span class="built_in">IPR_Operation</span>(result_Secret);</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//Decryption</span></span><br><span class="line">    <span class="built_in">first_StepEncryption</span>(result_Secret);</span><br><span class="line">    <span class="built_in">other_StepEncrtption</span>(<span class="number">1</span>);<span class="comment">//the 1 is meant decryption.</span></span><br><span class="line">    <span class="built_in">IPR_Operation</span>(result_Secret);</span><br><span class="line">    <span class="built_in">print</span>(<span class="number">0</span>);</span><br><span class="line">    <span class="built_in">Pri_ChangeToByte</span>(result_Secret);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span>* <span class="title">ChangeToBit</span><span class="params">(<span class="keyword">char</span> code[],<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> BinaryText[<span class="number">64</span>] = &#123;&#125;;</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;n; i++) &#123;</span><br><span class="line">        <span class="keyword">int</span> *temp =<span class="built_in">Change_bit</span>(code[i]);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;n; j++) &#123;</span><br><span class="line">            BinaryText[k++] = temp[j];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> BinaryText;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> * <span class="title">Change_bit</span><span class="params">(<span class="keyword">int</span> a)</span></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> flag[<span class="number">8</span>] = &#123;&#125;;</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">7</span>;</span><br><span class="line">    <span class="keyword">while</span> (a/<span class="number">2</span>!=<span class="number">0</span>) &#123;</span><br><span class="line">        flag[k--] = a % <span class="number">2</span>;</span><br><span class="line">        a = a / <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    flag[k] = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">return</span> flag;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> * <span class="title">Change_bit_S</span><span class="params">(<span class="keyword">int</span> a)</span></span>&#123;</span><br><span class="line">    <span class="keyword">static</span> <span class="keyword">int</span> flag[<span class="number">4</span>] = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">while</span> (a/<span class="number">2</span>!=<span class="number">0</span>) &#123;</span><br><span class="line">        flag[k++] = a % <span class="number">2</span>;</span><br><span class="line">        a = a / <span class="number">2</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(a == <span class="number">1</span>)</span><br><span class="line">    flag[k] = <span class="number">1</span>;</span><br><span class="line">    <span class="keyword">return</span> flag;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">set_16wheelKey</span><span class="params">(<span class="keyword">int</span> *bit_SecretKey)</span></span>&#123;</span><br><span class="line">    <span class="comment">//substitution selection 1</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">56</span>; i++) &#123;</span><br><span class="line">        Secret_KeyOf16[<span class="number">0</span>].subKey[i] = bit_SecretKey[subSelect_table1[i]<span class="number">-1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//C0 D0</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">28</span>; i++) &#123;</span><br><span class="line">        Secret_KeyOf16[<span class="number">0</span>].C[i] = Secret_KeyOf16[<span class="number">0</span>].subKey[i];</span><br><span class="line">        Secret_KeyOf16[<span class="number">0</span>].D[i] = Secret_KeyOf16[<span class="number">0</span>].subKey[i+<span class="number">28</span>];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span> ; i&lt;<span class="number">17</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span>(moveLeft_table[i] == <span class="number">1</span>)&#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">27</span>; j++) &#123;</span><br><span class="line">            Secret_KeyOf16[i].C[j] = Secret_KeyOf16[i<span class="number">-1</span>].C[j+<span class="number">1</span>];</span><br><span class="line">            Secret_KeyOf16[i].D[j] = Secret_KeyOf16[i<span class="number">-1</span>].D[j+<span class="number">1</span>];</span><br><span class="line">        &#125;</span><br><span class="line">        Secret_KeyOf16[i].C[<span class="number">27</span>] = Secret_KeyOf16[i<span class="number">-1</span>].C[<span class="number">0</span>];</span><br><span class="line">        Secret_KeyOf16[i].D[<span class="number">27</span>] = Secret_KeyOf16[i<span class="number">-1</span>].D[<span class="number">0</span>];</span><br><span class="line">        &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">26</span>; j++) &#123;</span><br><span class="line">                Secret_KeyOf16[i].C[j] = Secret_KeyOf16[i<span class="number">-1</span>].C[j+<span class="number">2</span>];</span><br><span class="line">                Secret_KeyOf16[i].D[j] = Secret_KeyOf16[i<span class="number">-1</span>].D[j+<span class="number">2</span>];</span><br><span class="line">            &#125;</span><br><span class="line">            Secret_KeyOf16[i].C[<span class="number">26</span>] = Secret_KeyOf16[i<span class="number">-1</span>].C[<span class="number">0</span>];</span><br><span class="line">            Secret_KeyOf16[i].C[<span class="number">27</span>] = Secret_KeyOf16[i<span class="number">-1</span>].C[<span class="number">1</span>];</span><br><span class="line">            Secret_KeyOf16[i].D[<span class="number">26</span>] = Secret_KeyOf16[i<span class="number">-1</span>].D[<span class="number">0</span>];</span><br><span class="line">            Secret_KeyOf16[i].D[<span class="number">27</span>] = Secret_KeyOf16[i<span class="number">-1</span>].D[<span class="number">1</span>];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//subKey1 ... subKey16</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i&lt;<span class="number">17</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">int</span> flag[<span class="number">56</span>] = &#123;&#125;;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">28</span>; j++) &#123;</span><br><span class="line">            flag[j] = Secret_KeyOf16[i].C[j];</span><br><span class="line">            flag[j+<span class="number">28</span>] = Secret_KeyOf16[i].D[j];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">48</span>; j++) &#123;</span><br><span class="line">            Secret_KeyOf16[i].subKey[j] = flag[subSelect_table2[j]<span class="number">-1</span>];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//print the result of secret key.</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i&lt;<span class="number">17</span>; i++) &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;N = %d\n&quot;</span>,i);</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;C%d：&quot;</span>,i);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">28</span>; j++) &#123;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Secret_KeyOf16[i].C[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;D%d：&quot;</span>,i);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">28</span>; j++) &#123;</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Secret_KeyOf16[i].D[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;子密钥%d：&quot;</span>,i);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">48</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Secret_KeyOf16[i].subKey[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n\n&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">first_StepEncryption</span><span class="params">(<span class="keyword">int</span> *bit_PlainText)</span></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">32</span>; i++) &#123;</span><br><span class="line">        Encryption_Pro[<span class="number">0</span>].L[i] = bit_PlainText[init_subIP[i]<span class="number">-1</span>];</span><br><span class="line">        Encryption_Pro[<span class="number">0</span>].R[i] = bit_PlainText[init_subIP[i+<span class="number">32</span>]<span class="number">-1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">other_StepEncrtption</span><span class="params">(<span class="keyword">int</span> flag)</span></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i&lt;<span class="number">17</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">48</span>; j++) &#123;</span><br><span class="line">            <span class="comment">//selection</span></span><br><span class="line">            Encryption_Pro[i].select_Operation[j] = Encryption_Pro[i<span class="number">-1</span>].R[sel_E[j]<span class="number">-1</span>];</span><br><span class="line">            <span class="comment">//secretion operation</span></span><br><span class="line">            <span class="keyword">if</span>(flag == <span class="number">0</span>)</span><br><span class="line">            Encryption_Pro[i].secretKey_Operation[j] =Secret_KeyOf16[i].subKey[j]^Encryption_Pro[i].select_Operation[j];</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">                Encryption_Pro[i].secretKey_Operation[j] =Secret_KeyOf16[<span class="number">17</span>-i].subKey[j]^Encryption_Pro[i].select_Operation[j];</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// Box of S</span></span><br><span class="line">        <span class="built_in">Box_operation</span>(Encryption_Pro[i].secretKey_Operation,i);</span><br><span class="line">        <span class="comment">// XOR operation</span></span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">32</span>; j++) &#123;</span><br><span class="line">            Encryption_Pro[i].L[j] = Encryption_Pro[i<span class="number">-1</span>].R[j];</span><br><span class="line">            Encryption_Pro[i].R[j] = Encryption_Pro[i<span class="number">-1</span>].L[j]^Encryption_Pro[i].boxOf_S[P_Table[j]<span class="number">-1</span>];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Box_operation</span><span class="params">(<span class="keyword">int</span> *a,<span class="keyword">int</span> n)</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> sum = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">48</span>; i += <span class="number">6</span>) &#123;</span><br><span class="line">        <span class="keyword">int</span> flag1 = BoxOf_S[i/<span class="number">6</span>][a[i]*<span class="number">2</span>+a[i+<span class="number">5</span>]][a[i+<span class="number">1</span>]*<span class="number">8</span>+a[i+<span class="number">2</span>]*<span class="number">4</span>+a[i+<span class="number">3</span>]*<span class="number">2</span>+a[i+<span class="number">4</span>]];</span><br><span class="line">        <span class="keyword">int</span> flag[<span class="number">4</span>] = &#123;<span class="number">0</span>&#125;;</span><br><span class="line">        <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">while</span> (flag1/<span class="number">2</span>!=<span class="number">0</span>) &#123;</span><br><span class="line">            flag[k++] = flag1 % <span class="number">2</span>;</span><br><span class="line">            flag1 = flag1 / <span class="number">2</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span>(flag1 == <span class="number">1</span>)</span><br><span class="line">        flag[k] = <span class="number">1</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">3</span>; j&gt;=<span class="number">0</span>; j--) &#123;</span><br><span class="line">            Encryption_Pro[n].boxOf_S[sum++] = flag[j];</span><br><span class="line">            </span><br><span class="line">        &#125;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">IPR_Operation</span><span class="params">(<span class="keyword">int</span> result[])</span></span>&#123;</span><br><span class="line">    <span class="keyword">int</span> temp[<span class="number">64</span>] = &#123;&#125;;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>;i&lt;<span class="number">32</span> ; i++) &#123;</span><br><span class="line">        temp[i] = Encryption_Pro[<span class="number">16</span>].R[i];</span><br><span class="line">        temp[<span class="number">32</span>+i] = Encryption_Pro[<span class="number">16</span>].L[i];</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span> ; i&lt;<span class="number">64</span>; i++) &#123;</span><br><span class="line">        result[i] = temp[IPR_Table[i]<span class="number">-1</span>];</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">print</span><span class="params">(<span class="keyword">int</span> flag)</span></span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; <span class="number">17</span> ; i++) &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\nN = %d\n&quot;</span>,i);</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;选择运算：&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">48</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Encryption_Pro[i].select_Operation[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n子密钥加：&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">48</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Encryption_Pro[i].secretKey_Operation[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\nS盒：&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">32</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Encryption_Pro[i].boxOf_S[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\nL：&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">32</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Encryption_Pro[i].L[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\nR：&quot;</span>);</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j&lt;<span class="number">32</span>; j++) &#123;</span><br><span class="line">            <span class="keyword">if</span>(j%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; j) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">            <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,Encryption_Pro[i].R[j]);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span>(flag == <span class="number">0</span>)</span><br><span class="line">        cout&lt;&lt;<span class="string">&quot;the result of secret text: &quot;</span>&lt;&lt;endl;</span><br><span class="line">    <span class="keyword">else</span></span><br><span class="line">        cout&lt;&lt;<span class="string">&quot;the result of plain text: &quot;</span>&lt;&lt;endl;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">64</span>; i++) &#123;</span><br><span class="line">        <span class="keyword">if</span> (i%<span class="number">8</span> == <span class="number">0</span> &amp;&amp; i != <span class="number">0</span>) <span class="built_in">printf</span>(<span class="string">&quot; &quot;</span>);</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,result_Secret[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Pri_ChangeToByte</span><span class="params">(<span class="keyword">int</span> secretKey[])</span></span>&#123;</span><br><span class="line">    <span class="keyword">char</span> temp[<span class="number">8</span>] = &#123;&#125;;</span><br><span class="line">    <span class="keyword">int</span> k = <span class="number">0</span>;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">64</span>; i+=<span class="number">8</span>) &#123;</span><br><span class="line">        <span class="keyword">int</span> sum = <span class="number">0</span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = i; j&lt;i+<span class="number">8</span>; j++) &#123;</span><br><span class="line">            sum += secretKey[j] * <span class="built_in">pow</span>(<span class="number">2</span>,<span class="number">7</span>-j%<span class="number">8</span>);</span><br><span class="line">        &#125;</span><br><span class="line">        temp[k++] = sum;</span><br><span class="line">    &#125;</span><br><span class="line">    cout&lt;&lt;<span class="string">&quot;the plaintext of 8 byte is :&quot;</span>&lt;&lt;endl;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i&lt;<span class="number">8</span>; i++) &#123;</span><br><span class="line">        <span class="built_in">printf</span>(<span class="string">&quot;%c&quot;</span>,temp[i]);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;\n&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Charles Yan</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.charlesyan.cn/2021/04/17/DES%E7%AE%97%E6%B3%95%E5%85%A8%E8%A7%A3/">https://www.charlesyan.cn/2021/04/17/DES%E7%AE%97%E6%B3%95%E5%85%A8%E8%A7%A3/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.charlesyan.cn" target="_blank">路漫漫其修远兮，吾将上下而求索</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E7%AE%97%E6%B3%95/">算法</a><a class="post-meta__tags" href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a><a class="post-meta__tags" href="/tags/%E5%AF%86%E7%A0%81%E5%AD%A6/">密码学</a></div><div class="post_share"><div class="social-share" data-image="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=464616017,1330542316&amp;fm=26&amp;gp=0.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/IMG_0003.jpeg" target="_blank"><img class="post-qr-code-img" src="/img/IMG_0003.jpeg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/IMG_0004.jpeg" target="_blank"><img class="post-qr-code-img" src="/img/IMG_0004.jpeg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/04/23/RSA%E5%AF%86%E7%A0%81/"><img class="prev-cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/7801.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info"></div></div></a></div><div class="next-post pull-right"><a href="/2020/12/27/%E5%88%86%E6%94%AF%E9%99%90%E7%95%8C%E6%B3%95/"><img class="next-cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/3989.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info"></div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/01/30/深度优先遍历/" title="6-1 邻接矩阵存储图的深度优先遍历 (20 分)"><img class="cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/3989.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-30</div><div class="title">6-1 邻接矩阵存储图的深度优先遍历 (20 分)</div></div></a></div><div><a href="/2020/01/21/汉诺塔非递归实现c语言版/" title="汉诺塔非递归实现 C语言版"><img class="cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/12998.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-21</div><div class="title">汉诺塔非递归实现 C语言版</div></div></a></div><div><a href="/2020/01/20/哈夫曼树--修理牧场/" title="2-5 修理牧场 (35分) 哈夫曼树例题 c与c++鸳鸯解法 详细解释"><img class="cover" src="https://img-blog.csdnimg.cn/20191207174941948.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1Zpc3RvcnNZYW4=,size_16,color_FFFFFF,t_70" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-20</div><div class="title">2-5 修理牧场 (35分) 哈夫曼树例题 c与c++鸳鸯解法 详细解释</div></div></a></div><div><a href="/2020/01/20/树种统计/" title="PTA 树种统计  c语言-------二叉搜索树 详细解释"><img class="cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/7801.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-20</div><div class="title">PTA 树种统计  c语言-------二叉搜索树 详细解释</div></div></a></div><div><a href="/2020/01/19/leeCode报错问题1/" title="LeeCode第二题常见报错"><img class="cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/12998.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-19</div><div class="title">LeeCode第二题常见报错</div></div></a></div><div><a href="/2020/01/19/汉诺塔递归实现c语言版/" title="汉诺塔递归实现c语言版"><img class="cover" src="https://gitee.com/yan_zilong/picgo/raw/master/img/Blog/post/密码学复习提纲/3989.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-19</div><div class="title">汉诺塔递归实现c语言版</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#DES%E7%AE%97%E6%B3%95%E5%85%A8%E8%A7%A3"><span class="toc-number">1.</span> <span class="toc-text">DES算法全解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E4%BB%80%E4%B9%88%E6%98%AFDES%E7%AE%97%E6%B3%95"><span class="toc-number">1.1.</span> <span class="toc-text">一、什么是DES算法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81DES%E7%9A%84%E5%8A%A0%E5%AF%86%E8%BF%87%E7%A8%8B"><span class="toc-number">1.2.</span> <span class="toc-text">二、DES的加密过程</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89%E3%80%81DES%E7%9A%84%E7%AE%97%E6%B3%95%E7%BB%86%E8%8A%82"><span class="toc-number">1.3.</span> <span class="toc-text">三、DES的算法细节</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-%E5%88%9B%E5%BB%BA16%E4%B8%AA%E5%AD%90%E7%A7%98%E9%92%A5%EF%BC%8C%E6%AF%8F%E4%B8%AA%E9%95%BF48%E6%AF%94%E7%89%B9"><span class="toc-number">1.3.1.</span> <span class="toc-text">1.     创建16个子秘钥，每个长48比特</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-%E6%98%8E%E6%96%87%E5%88%9D%E5%A7%8B%E5%8F%98%E6%8D%A2"><span class="toc-number">1.3.2.</span> <span class="toc-text">2. 明文初始变换</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-%E5%8A%A0%E5%AF%86%E5%87%BD%E6%95%B0"><span class="toc-number">1.3.3.</span> <span class="toc-text">3. 加密函数</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-%E8%A7%A3%E5%AF%86%E8%BF%87%E7%A8%8B"><span class="toc-number">1.3.4.</span> <span class="toc-text">4. 解密过程</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=464616017,1330542316&amp;fm=26&amp;gp=0.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By Charles Yan</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a target="_blank" rel="noopener" href="https:charlesyan.cn/">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="rightside.chat_btn"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>if (!window.MathJax) {
  window.MathJax = {
    loader: {
      source: {
        '[tex]/amsCd': '[tex]/amscd'
      }
    },
    tex: {
      inlineMath: [ ['$','$'], ["\\(","\\)"]],
      tags: 'ams'
    },
    options: {
      renderActions: {
        findScript: [10, doc => {
          for (const node of document.querySelectorAll('script[type^="math/tex"]')) {
            const display = !!node.type.match(/; *mode=display/)
            const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display)
            const text = document.createTextNode('')
            node.parentNode.replaceChild(text, node)
            math.start = {node: text, delim: '', n: 0}
            math.end = {node: text, delim: '', n: 0}
            doc.math.push(math)
          }
        }, ''],
        addClass: [200,() => {
          document.querySelectorAll('mjx-container:not([display=\'true\']').forEach( node => {
            const target = node.parentNode
            if (!target.classList.contains('has-jax')) {
              target.classList.add('mathjax-overflow')
            }
          })
        }, '', false]
      }
    }
  }
  
  const script = document.createElement('script')
  script.src = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js'
  script.id = 'MathJax-script'
  script.async = true
  document.head.appendChild(script)
} else {
  MathJax.startup.document.state(0)
  MathJax.texReset()
  MathJax.typeset()
}</script><script>if (document.getElementsByClassName('mermaid').length) {
  if (window.mermaidJsLoad) mermaid.init()
  else {
    getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(() => {
      window.mermaidJsLoad = true
      mermaid.initialize({
        theme: 'default',
      })
      false && mermaid.init()
    })
  }
}</script><script>(()=>{
  const $countDom = document.getElementById('twikoo-count')
  const init = () => {
    twikoo.init(Object.assign({
      el: '#twikoo-wrap',
      envId: 'https://twikoo-beta-tawny.vercel.app/',
      region: ''
    }, null))
  }

  const getCount = () => {
    twikoo.getCommentsCount({
      envId: 'https://twikoo-beta-tawny.vercel.app/',
      region: '',
      urls: [window.location.pathname],
      includeReply: false
    }).then(function (res) {
      $countDom.innerText = res[0].count
    }).catch(function (err) {
      console.error(err);
    });
  }

  const loadTwikoo = (bool = false) => {
    if (typeof twikoo === 'object') {
      init()
      bool && $countDom && setTimeout(getCount,0)
    } else {
      getScript('https://cdn.jsdelivr.net/npm/twikoo/dist/twikoo.all.min.js').then(()=> {
        init()
        bool && $countDom && setTimeout(getCount,0)
      })
    }
  }

  if ('Twikoo' === 'Twikoo' || !false) {
    if (false) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
    else loadTwikoo(true)
  } else {
    window.loadOtherComment = () => {
      loadTwikoo()
    }
  }
})()</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>